﻿using System;
using System.Collections.Generic;
using System.Text;

using HoldemGame;
using Layers;

namespace HoldemHook
{
    public class FTTableParser
    {
        ITextOutEventSource _table;

        IGame _target;
        Mosaic mosaic = new Mosaic();

        string sTotalPot = "Total pot:";
        List<String> Skip = new List<String>(new string[] { "GET CHIPS", "LAST HAND", "STAND UP", "PLAY REAL MONEY", "LAYOUT", "OPTIONS", "LOBBY", "STATS","FOLD","RAISE","BET","CHECK" });
        
        public FTTableParser(ITextOutEventSource table, IGame target)
        {
            _target = target;
            _table = table;
            _table.TextOutEvent += new EventHandler<TextOutEventArgs>(OnNewMessage);
        }

        double ParseMoney(string msg)
        {
            msg = msg.Trim();
            if (msg[0] == '$')
                msg = msg.Substring(1);
            return double.Parse(msg);
        }
        static int nn = 0;
        void OnNewMessage(object sender, TextOutEventArgs e)
        {
            if (e.Message.StartsWith(sTotalPot))
                TotalPot(ParseMoney(e.Message.Substring(sTotalPot.Length)));
            else if (e.Message.StartsWith("Dealer:"))
            {

            }
            else if (Skip.IndexOf(e.Message) >= 0)
            {

            }
            else
            {
                mosaic.Add(e.Point.X, e.Point.Y, e.Message, 0);
                if (++nn % 9 == 0)
                    MyLogger.WriteLine(mosaic.ToString());
            }
        }

        void TotalPot(double pot)
        {
            _target.State.Pot = pot;
        }

    }
}
